﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TFSTools.TFSLibrary
{
    public sealed class TFSAttachment : TFSServerEntity
    {
        private Attachment serverAttachment;

        internal TFSAttachment(ITFSConnection connection, Attachment attachment)
            : base(connection)
        {
            this.serverAttachment = attachment;
        }

        internal Attachment ServerEntity { get { return this.serverAttachment; } }

        public override string ToString() { return this.serverAttachment.ToString(); }
    }

    public sealed class TFSAttachmentCollection : TFSServerEntityCollection<TFSAttachment>
    {
        public TFSAttachmentCollection(ITFSConnection connection)
            : base(connection)
        {
        }

        public TFSAttachmentCollection(ITFSConnection connection, IList<TFSAttachment> list)
            : base(connection, list)
        {
        }

        public TFSAttachmentCollection(ITFSConnection connection, int capacity)
            : base(connection, capacity)
        {
        }

        internal static TFSAttachmentCollection Create(ITFSConnection connection, AttachmentCollection collection)
        {
            var list = new List<TFSAttachment>(collection.Count);

            foreach (Attachment attachment in collection)
            {
                list.Add(new TFSAttachment(connection, attachment));
            }

            return new TFSAttachmentCollection(connection, list);
        }
    }
}
